<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Mode Switching (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Mode Switching (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Mode Switching (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Target-Macros.html" rel="up" title="Target Macros">
<link href="Target-Attributes.html" rel="next" title="Target Attributes">
<link href="Floating-Point.html" rel="prev" title="Floating Point">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>


</head>

<body lang="en">
<div class="section-level-extent" id="Mode-Switching">
<div class="nav-panel">
<p>
Next: <a href="Target-Attributes.html" accesskey="n" rel="next">Defining target-specific uses of <code class="code">__attribute__</code></a>, Previous: <a href="Floating-Point.html" accesskey="p" rel="prev">Cross Compilation and Floating Point</a>, Up: <a href="Target-Macros.html" accesskey="u" rel="up">Target Description Macros and Functions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Mode-Switching-Instructions"><span>18.23 Mode Switching Instructions<a class="copiable-link" href="#Mode-Switching-Instructions"> &para;</a></span></h3>
<a class="index-entry-id" id="index-mode-switching"></a>
<p>The following macros control mode switching optimizations:
</p>
<dl class="first-deffn first-defmac-alias-first-deffn">
<dt class="deffn defmac-alias-deffn" id="index-OPTIMIZE_005fMODE_005fSWITCHING"><span class="category-def">Macro: </span><span><strong class="def-name">OPTIMIZE_MODE_SWITCHING</strong> <var class="def-var-arguments">(<var class="var">entity</var>)</var><a class="copiable-link" href="#index-OPTIMIZE_005fMODE_005fSWITCHING"> &para;</a></span></dt>
<dd><p>Define this macro if the port needs extra instructions inserted for mode
switching in an optimizing compilation.
</p>
<p>For an example, the SH4 can perform both single and double precision
floating point operations, but to perform a single precision operation,
the FPSCR PR bit has to be cleared, while for a double precision
operation, this bit has to be set.  Changing the PR bit requires a general
purpose register as a scratch register, hence these FPSCR sets have to
be inserted before reload, i.e. you cannot put this into instruction emitting
or <code class="code">TARGET_MACHINE_DEPENDENT_REORG</code>.
</p>
<p>You can have multiple entities that are mode-switched, and select at run time
which entities actually need it.  <code class="code">OPTIMIZE_MODE_SWITCHING</code> should
return nonzero for any <var class="var">entity</var> that needs mode-switching.
If you define this macro, you also have to define
<code class="code">NUM_MODES_FOR_MODE_SWITCHING</code>, <code class="code">TARGET_MODE_NEEDED</code>,
<code class="code">TARGET_MODE_PRIORITY</code> and <code class="code">TARGET_MODE_EMIT</code>.
<code class="code">TARGET_MODE_AFTER</code>, <code class="code">TARGET_MODE_ENTRY</code>, and <code class="code">TARGET_MODE_EXIT</code>
are optional.
</p></dd></dl>

<dl class="first-deffn first-defmac-alias-first-deffn">
<dt class="deffn defmac-alias-deffn" id="index-NUM_005fMODES_005fFOR_005fMODE_005fSWITCHING"><span class="category-def">Macro: </span><span><strong class="def-name">NUM_MODES_FOR_MODE_SWITCHING</strong><a class="copiable-link" href="#index-NUM_005fMODES_005fFOR_005fMODE_005fSWITCHING"> &para;</a></span></dt>
<dd><p>If you define <code class="code">OPTIMIZE_MODE_SWITCHING</code>, you have to define this as
initializer for an array of integers.  Each initializer element
N refers to an entity that needs mode switching, and specifies the number
of different modes that might need to be set for this entity.
The position of the initializer in the initializer&mdash;starting counting at
zero&mdash;determines the integer that is used to refer to the mode-switched
entity in question.
In macros that take mode arguments / yield a mode result, modes are
represented as numbers 0 &hellip; N &minus; 1.  N is used to specify that no mode
switch is needed / supplied.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fMODE_005fEMIT"><span class="category-def">Target Hook: </span><span><code class="def-type">void</code> <strong class="def-name">TARGET_MODE_EMIT</strong> <code class="def-code-arguments">(int <var class="var">entity</var>, int <var class="var">mode</var>, int <var class="var">prev_mode</var>, HARD_REG_SET <var class="var">regs_live</var>)</code><a class="copiable-link" href="#index-TARGET_005fMODE_005fEMIT"> &para;</a></span></dt>
<dd><p>Generate one or more insns to set <var class="var">entity</var> to <var class="var">mode</var>.
<var class="var">hard_reg_live</var> is the set of hard registers live at the point where
the insn(s) are to be inserted. <var class="var">prev_moxde</var> indicates the mode
to switch from. Sets of a lower numbered entity will be emitted before
sets of a higher numbered entity to a mode of the same or lower priority.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fMODE_005fNEEDED"><span class="category-def">Target Hook: </span><span><code class="def-type">int</code> <strong class="def-name">TARGET_MODE_NEEDED</strong> <code class="def-code-arguments">(int <var class="var">entity</var>, rtx_insn *<var class="var">insn</var>)</code><a class="copiable-link" href="#index-TARGET_005fMODE_005fNEEDED"> &para;</a></span></dt>
<dd><p><var class="var">entity</var> is an integer specifying a mode-switched entity.
If <code class="code">OPTIMIZE_MODE_SWITCHING</code> is defined, you must define this macro
to return an integer value not larger than the corresponding element
in <code class="code">NUM_MODES_FOR_MODE_SWITCHING</code>, to denote the mode that <var class="var">entity</var>
must be switched into prior to the execution of <var class="var">insn</var>.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fMODE_005fAFTER"><span class="category-def">Target Hook: </span><span><code class="def-type">int</code> <strong class="def-name">TARGET_MODE_AFTER</strong> <code class="def-code-arguments">(int <var class="var">entity</var>, int <var class="var">mode</var>, rtx_insn *<var class="var">insn</var>)</code><a class="copiable-link" href="#index-TARGET_005fMODE_005fAFTER"> &para;</a></span></dt>
<dd><p><var class="var">entity</var> is an integer specifying a mode-switched entity.
If this macro is defined, it is evaluated for every <var class="var">insn</var> during mode
switching.  It determines the mode that an insn results
in (if different from the incoming mode).
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fMODE_005fENTRY"><span class="category-def">Target Hook: </span><span><code class="def-type">int</code> <strong class="def-name">TARGET_MODE_ENTRY</strong> <code class="def-code-arguments">(int <var class="var">entity</var>)</code><a class="copiable-link" href="#index-TARGET_005fMODE_005fENTRY"> &para;</a></span></dt>
<dd><p>If this macro is defined, it is evaluated for every <var class="var">entity</var> that
needs mode switching.  It should evaluate to an integer, which is a mode
that <var class="var">entity</var> is assumed to be switched to at function entry.
If <code class="code">TARGET_MODE_ENTRY</code> is defined then <code class="code">TARGET_MODE_EXIT</code>
must be defined.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fMODE_005fEXIT"><span class="category-def">Target Hook: </span><span><code class="def-type">int</code> <strong class="def-name">TARGET_MODE_EXIT</strong> <code class="def-code-arguments">(int <var class="var">entity</var>)</code><a class="copiable-link" href="#index-TARGET_005fMODE_005fEXIT"> &para;</a></span></dt>
<dd><p>If this macro is defined, it is evaluated for every <var class="var">entity</var> that
needs mode switching.  It should evaluate to an integer, which is a mode
that <var class="var">entity</var> is assumed to be switched to at function exit.
If <code class="code">TARGET_MODE_EXIT</code> is defined then <code class="code">TARGET_MODE_ENTRY</code>
must be defined.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fMODE_005fPRIORITY"><span class="category-def">Target Hook: </span><span><code class="def-type">int</code> <strong class="def-name">TARGET_MODE_PRIORITY</strong> <code class="def-code-arguments">(int <var class="var">entity</var>, int <var class="var">n</var>)</code><a class="copiable-link" href="#index-TARGET_005fMODE_005fPRIORITY"> &para;</a></span></dt>
<dd><p>This macro specifies the order in which modes for <var class="var">entity</var>
are processed. 0 is the highest priority,
<code class="code">NUM_MODES_FOR_MODE_SWITCHING[<var class="var">entity</var>] - 1</code> the lowest.
The value of the macro should be an integer designating a mode
for <var class="var">entity</var>.  For any fixed <var class="var">entity</var>, <code class="code">mode_priority</code>
(<var class="var">entity</var>, <var class="var">n</var>) shall be a bijection in 0 &hellip;
<code class="code">num_modes_for_mode_switching[<var class="var">entity</var>] - 1</code>.
</p></dd></dl>

</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Target-Attributes.html">Defining target-specific uses of <code class="code">__attribute__</code></a>, Previous: <a href="Floating-Point.html">Cross Compilation and Floating Point</a>, Up: <a href="Target-Macros.html">Target Description Macros and Functions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
